package com.itic.mall.mobile.users.helper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.applications.sys.code.persistence.model.CodeDetail;
import com.itic.appbase.applications.sys.code.persistence.model.CodeDetailExample;
import com.itic.appbase.applications.sys.code.persistence.model.CodeDetailExample.Criteria;
import com.itic.appbase.applications.sys.code.service.CodeDetailService;
import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.appbase.framework.utils.ValueHelper;
import com.itic.mall.mobile.base.BaseMobileInterface;
import com.itic.mall.system.market.markethelper.persistence.model.MarketHelper;
import com.itic.mall.system.market.markethelper.persistence.model.MarketHelperExample;
import com.itic.mall.system.market.markethelper.service.MarketHelperService;

/**
 * 邀请入驻接口
 * @author libin
 * @time 2017-12-4
 */

@Controller
@RequestMapping(value="/mobile/users/helper")
public class HelperInterface extends BaseMobileInterface{
	
	private static String HELPER_DM_NAME = "T_DM_MARKET_HELPER_CATEGORY";
	
	@Autowired
	private CodeDetailService codeDetailService;
	@Autowired
	private MarketHelperService marketHelperService;
	/**
	 * 云店主邀请VIP用户注册
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/categorys")
	@ResponseBody
	public Map<String,Object> categorys( HttpServletRequest request,HttpServletResponse response ){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	    	CodeDetailExample example = new CodeDetailExample();
	    	Criteria criteria = example.createCriteria();
	    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
	    	criteria.andTypeEqualTo(HELPER_DM_NAME);
	    	List<CodeDetail> list = codeDetailService.list(example);
	    	resultMap.put(DATA, ValueHelper.tranList2MapList(list, new String[] { "id","parentId","type","orderNo","isEffective","createTime","updateTime","orgCode","createUser","treeCode" }));
	    	errorCode = SUCCESS_ERROR_CODE;
	       	errorMsg = SUCCESS_ERROR_MSG;
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("HelperInterface", "categorys", e.toString(),"问题类别",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	/**
	 * 云店主邀请VIP用户注册
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/list")
	@ResponseBody
	public Map<String,Object> list( HttpServletRequest request,HttpServletResponse response, String code ){
		String errorCode = PARAM_ERROR_CODE;
	   	String errorMsg = PARAM_ERROR_MSG;
	    Map<String, Object> resultMap = new HashMap<String,Object>();
	    try{
	   		
	    	if( StringHelper.isNotBlank(code) ){
	    		MarketHelperExample example = new MarketHelperExample();
	    		com.itic.mall.system.market.markethelper.persistence.model.MarketHelperExample.Criteria criteria = example.createCriteria();
	    		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
	    		criteria.andCodeEqualTo(code);
	    		List<MarketHelper> list = marketHelperService.list(example);
	    		resultMap.put(DATA, ValueHelper.tranList2MapList(list, new String[] { "id","isEffective","createTime","updateTime","orgCode","createUser","reorder","code","note" }));
	    		errorCode = SUCCESS_ERROR_CODE;
		       	errorMsg = SUCCESS_ERROR_MSG;
	    	}
	    	
	    }catch(Exception e){
	    	errorCode = SERVER_ERROR_CODE;
	       	errorMsg = SERVER_ERROR_MSG;
	   		logException("HelperInterface", "list", e.toString(),"问题类别下的列表",e);
	    }
	    resultMap.put(CODE, errorCode);
	    resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
	    return resultMap;
	}
	
	
}
